/*
 * @Author: moeWang
 * @Date: 2022-03-04 15:38:51
 * @LastEditTime: 2022-03-04 15:38:52
 * @LastEditors: moeWang
 * @Description: 
 * @FilePath: \nest-web\src\logical\common\controller\base.controller.ts
 */
/*
 * @Author: moeWang
 * @Date: 2022-03-02 15:57:18
 * @LastEditTime: 2022-03-04 12:12:40
 * @LastEditors: moeWang
 * @Description:
 * @FilePath: \nest-web\src\logical\common\services\base.service.ts
 */

import { BaseListResultModel } from '../models/BaseListResult.model';
import { BaseResultModel } from '../models/BaseResult.model';
import { Pagination } from '../models/Pagination.model';

export class BaseController {
  resultListData(
    obj: Array<any>,
    code: number,
    msg: string,
    pagination: Pagination,
  ): BaseListResultModel<any> {
    const rls: BaseListResultModel<any> = new BaseListResultModel();
    rls.setDatas(obj);
    rls.setError_code(code);
    rls.setError_msg(msg);
    rls.setPagination(pagination);
    return rls;
  }

  resultData(obj: any, code: number, msg: string): BaseResultModel<any> {
    const rs: BaseResultModel<any> = new BaseResultModel();
    rs.setData(obj);
    rs.setError_code(code);
    rs.setError_msg(msg);

    return rs;
  }

  getSuccessResultData(obj: any): BaseResultModel<any> {
    return this.resultData(obj, 200, '获取成功');
  }
  getFailedResultData(): BaseResultModel<Object> {
    return this.resultData(null, 200, '获取内容失败');
  }
  getNullResultData(): BaseResultModel<Object> {
    return this.resultData(null, 200, '无此条记录，请核准Id');
  }
  saveSuccessResultData(): BaseResultModel<Object> {
    return this.resultData(null, 200, '保存成功');
  }
  saveFailedResultData(msg: string): BaseResultModel<Object> {
    return this.resultData(null, 500, msg ? msg : '保存失败');
  }
  deleteSuccessResultData(): BaseResultModel<Object> {
    return this.resultData({}, 200, '删除成功');
  }
  deleteFailedResultData(msg: string): BaseResultModel<Object> {
    return this.resultData({}, 500, msg ? msg : '删除失败');
  }

  querySuccessResultListData(
    obj: Array<any>,
    pagination: Pagination,
  ): BaseListResultModel<any> {
    return this.resultListData(obj, 200, '查询成功', pagination);
  }
  queryFailedResultListData(pagination: Pagination): BaseListResultModel<any> {
    return this.resultListData([], 500, '查询失败', pagination);
  }

  queryValidFailedResultListData(
    pagination: Pagination,
    msg: string,
  ): BaseListResultModel<any> {
    return this.resultListData([], 500, msg, pagination);
  }

  detailFailedResultData(msg: string) {
    return this.resultData(null, 500, msg ? msg : '查询详细失败');
  }

  getNowDate() {
    return new Date(
      new Date().getTime() +
        Math.abs(new Date().getTimezoneOffset()) * 60 * 1000,
    );
  }
}
